import { Column, Entity, Index } from 'typeorm'
import { BaseEntity } from './BaseEntity'
import { ApiProperty } from '@nestjs/swagger'
import { IsDefined, IsNotEmpty, Max, MaxLength, Min } from 'class-validator'

@Entity('t_api')
export default class ApiEntity extends BaseEntity {
  @Index()
  @Column({
    comment: '所属项目id',
    name: 'project_id',
  })
  @ApiProperty({ description: '所属项目id' })
  @IsDefined({ message: '所属项目必填' })
  @IsNotEmpty({ message: '所属项目必填' })
  projectId: number

  @Column({
    comment: '接口名',
    length: 200,
  })
  @ApiProperty({ description: '接口名', maxLength: 200 })
  @IsDefined({ message: '接口名必填' })
  @IsNotEmpty({ message: '接口名必填' })
  @MaxLength(200, { message: '接口名最多200字符' })
  name: string

  @Column({
    comment: '请求方式',
    length: 6,
  })
  @ApiProperty({ description: '请求方式', enum: ['GET', 'POST', 'PUT', 'DELETE'], maxLength: 6 })
  @IsDefined({ message: '请求方式必填' })
  @IsNotEmpty({ message: '请求方式必填' })
  @MaxLength(6, { message: '请求方式最多6字符' })
  method: string

  @Column({
    comment: '接口URI',
    length: 200,
  })
  @ApiProperty({ description: '接口URI', maxLength: 200, uniqueItems: true })
  @IsDefined({ message: '接口URI必填' })
  @IsNotEmpty({ message: '接口URI必填' })
  @MaxLength(200, { message: '接口URI最多200字符' })
  uri: string

  @Column({
    comment: '是否启用(启用: 1, 禁用: 0)',
    type: 'tinyint',
  })
  @ApiProperty({ description: '是否启用', enum: [1, 0] })
  @IsDefined({ message: '是否启用必填' })
  @Min(0, { message: '启用: 1, 禁用: 0' })
  @Max(1, { message: '启用: 1, 禁用: 0' })
  enable: number

  @Column({
    comment: '自定义mock方法内容',
    type: 'text',
    name: 'mock_method_content',
    default: '',
  })
  @ApiProperty({ description: '自定义mock方法内容', maxLength: 3000 })
  mockMethodContent: string
}
